package com.jimikongjian.controller;

import com.jimikongjian.models.Photo;
import com.jimikongjian.models.ResponseMessage;
import com.jimikongjian.service.base.IPhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by fuxiuyang on 17/3/13.
 */
@RestController("photoController")
@RequestMapping(value = "/v1")
public class PhotoController {


    @Autowired
    @Qualifier("photoService")
    private IPhotoService photoService;


    /**
     * 将多个图片上传到服务器上
     * @param photo
     * @return
     */
    @RequestMapping(value = "/photo", method = RequestMethod.POST)
    @ResponseBody
    public ResponseMessage uploadPhoto(@RequestBody Photo photo){
        return photoService.uploadPhoto(photo);
    }


    /**
     * 通过id或者是相册的id，查询照片
     * @param id
     * @param albumId
     * @param start
     * @param length
     * @return
     */
    @RequestMapping(value = "/photo", method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage selectPhoto(@RequestParam(name = "id", defaultValue = "-1") Integer id,
                                       @RequestParam(name = "albumId", defaultValue = "-1") Integer albumId,
                                       @RequestParam(name = "start", defaultValue = "0") Integer start,
                                       @RequestParam(name = "length", defaultValue = "10") Integer length){
        if (id != -1){
            return photoService.selectPhotoById(id);
        }
        return photoService.selectPhotoByAlbumId(albumId, start, length);
    }
}
